import requests

from log.log import test_log


#topic为要发送的MQ主题，messageBody为要发送的消息
def send_mq(topic,messageBody):
    
    #登录请求
    login_url = 'http://192.168.166.1:8080/login/login.do'
    #请求参数
    payload = {'username': 'admin', 'password': 'hfUP%uSIEt$w'}

    response = requests.post(login_url, data=payload)

    #获取ssessionId 
    sessionId=response.json()['data']['sessionId']
    #发送mq消息
    SendMq_url='http://192.168.166.1:8080//topic/sendTopicMessage.do'
    header={"Content-Type":"application/json","Cookie":"NG_TRANSLATE_LANG_KEY=%22en%22; JSESSIONID={}".format(sessionId)}
    data={
    "topic": topic,
    "key": "key",
    "tag": "tag",
    "messageBody": messageBody
    }
    SendMq_response=requests.post(url=SendMq_url,headers=header,json=data)
    test_log.info("mq发送成功")





# send_mq('USER_LOGIN_EVENT_TOPIC','{\"phone\":\"872442267810\",\"uid\":13941782}')